<?php
/** @var Core\Router $router */

// 添加全局中间件
$router->addGlobalMiddleware(\App\Middlewares\CorsMiddleware::class);

// 定义路由
$router->get('/', function($request) {
    return \Core\Response::make()->json(['message' => 'API Framework v3']);
});

$router->group('/api', function($router) {
    $router->get('/users', 'UserController@index');
    $router->get('/users/{id}', 'UserController@show')->where(['id' => '[0-9]+']);
    $router->post('/users', 'UserController@store');
    $router->put('/users/{id}', 'UserController@update')->where(['id' => '[0-9]+']);
    $router->delete('/users/{id}', 'UserController@delete')->where(['id' => '[0-9]+']);
}, [\App\Middlewares\AuthMiddleware::class]);

// 添加通配符路由来处理不存在的路径
$router->any('{any}', function($request) {
    return \Core\Response::make()
        ->status(404)
        ->json(['error' => 'Not Found']);
})->where(['any' => '.*']);